{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 数据加载和简单的数据探索"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-07-07T13:36:04.235027Z",
     "start_time": "2018-07-07T13:36:03.328587Z"
    }
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from sklearn import datasets\n",
    "from pyecharts import Scatter"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-07-07T12:06:52.078769Z",
     "start_time": "2018-07-07T12:06:52.047784Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_keys(['data', 'target', 'target_names', 'DESCR', 'feature_names'])"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "iris = datasets.load_iris()\n",
    "iris.keys()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-07-07T12:07:21.070432Z",
     "start_time": "2018-07-07T12:07:21.063435Z"
    },
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Iris Plants Database\n",
      "====================\n",
      "\n",
      "Notes\n",
      "-----\n",
      "Data Set Characteristics:\n",
      "    :Number of Instances: 150 (50 in each of three classes)\n",
      "    :Number of Attributes: 4 numeric, predictive attributes and the class\n",
      "    :Attribute Information:\n",
      "        - sepal length in cm\n",
      "        - sepal width in cm\n",
      "        - petal length in cm\n",
      "        - petal width in cm\n",
      "        - class:\n",
      "                - Iris-Setosa\n",
      "                - Iris-Versicolour\n",
      "                - Iris-Virginica\n",
      "    :Summary Statistics:\n",
      "\n",
      "    ============== ==== ==== ======= ===== ====================\n",
      "                    Min  Max   Mean    SD   Class Correlation\n",
      "    ============== ==== ==== ======= ===== ====================\n",
      "    sepal length:   4.3  7.9   5.84   0.83    0.7826\n",
      "    sepal width:    2.0  4.4   3.05   0.43   -0.4194\n",
      "    petal length:   1.0  6.9   3.76   1.76    0.9490  (high!)\n",
      "    petal width:    0.1  2.5   1.20  0.76     0.9565  (high!)\n",
      "    ============== ==== ==== ======= ===== ====================\n",
      "\n",
      "    :Missing Attribute Values: None\n",
      "    :Class Distribution: 33.3% for each of 3 classes.\n",
      "    :Creator: R.A. Fisher\n",
      "    :Donor: Michael Marshall (MARSHALL%PLU@io.arc.nasa.gov)\n",
      "    :Date: July, 1988\n",
      "\n",
      "This is a copy of UCI ML iris datasets.\n",
      "http://archive.ics.uci.edu/ml/datasets/Iris\n",
      "\n",
      "The famous Iris database, first used by Sir R.A Fisher\n",
      "\n",
      "This is perhaps the best known database to be found in the\n",
      "pattern recognition literature.  Fisher's paper is a classic in the field and\n",
      "is referenced frequently to this day.  (See Duda & Hart, for example.)  The\n",
      "data set contains 3 classes of 50 instances each, where each class refers to a\n",
      "type of iris plant.  One class is linearly separable from the other 2; the\n",
      "latter are NOT linearly separable from each other.\n",
      "\n",
      "References\n",
      "----------\n",
      "   - Fisher,R.A. \"The use of multiple measurements in taxonomic problems\"\n",
      "     Annual Eugenics, 7, Part II, 179-188 (1936); also in \"Contributions to\n",
      "     Mathematical Statistics\" (John Wiley, NY, 1950).\n",
      "   - Duda,R.O., & Hart,P.E. (1973) Pattern Classification and Scene Analysis.\n",
      "     (Q327.D83) John Wiley & Sons.  ISBN 0-471-22361-1.  See page 218.\n",
      "   - Dasarathy, B.V. (1980) \"Nosing Around the Neighborhood: A New System\n",
      "     Structure and Classification Rule for Recognition in Partially Exposed\n",
      "     Environments\".  IEEE Transactions on Pattern Analysis and Machine\n",
      "     Intelligence, Vol. PAMI-2, No. 1, 67-71.\n",
      "   - Gates, G.W. (1972) \"The Reduced Nearest Neighbor Rule\".  IEEE Transactions\n",
      "     on Information Theory, May 1972, 431-433.\n",
      "   - See also: 1988 MLC Proceedings, 54-64.  Cheeseman et al\"s AUTOCLASS II\n",
      "     conceptual clustering system finds 3 classes in the data.\n",
      "   - Many, many more ...\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print(iris.DESCR)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-07-07T12:07:47.092009Z",
     "start_time": "2018-07-07T12:07:47.068022Z"
    },
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[5.1, 3.5, 1.4, 0.2],\n",
       "       [4.9, 3. , 1.4, 0.2],\n",
       "       [4.7, 3.2, 1.3, 0.2],\n",
       "       [4.6, 3.1, 1.5, 0.2],\n",
       "       [5. , 3.6, 1.4, 0.2],\n",
       "       [5.4, 3.9, 1.7, 0.4],\n",
       "       [4.6, 3.4, 1.4, 0.3],\n",
       "       [5. , 3.4, 1.5, 0.2],\n",
       "       [4.4, 2.9, 1.4, 0.2],\n",
       "       [4.9, 3.1, 1.5, 0.1],\n",
       "       [5.4, 3.7, 1.5, 0.2],\n",
       "       [4.8, 3.4, 1.6, 0.2],\n",
       "       [4.8, 3. , 1.4, 0.1],\n",
       "       [4.3, 3. , 1.1, 0.1],\n",
       "       [5.8, 4. , 1.2, 0.2],\n",
       "       [5.7, 4.4, 1.5, 0.4],\n",
       "       [5.4, 3.9, 1.3, 0.4],\n",
       "       [5.1, 3.5, 1.4, 0.3],\n",
       "       [5.7, 3.8, 1.7, 0.3],\n",
       "       [5.1, 3.8, 1.5, 0.3],\n",
       "       [5.4, 3.4, 1.7, 0.2],\n",
       "       [5.1, 3.7, 1.5, 0.4],\n",
       "       [4.6, 3.6, 1. , 0.2],\n",
       "       [5.1, 3.3, 1.7, 0.5],\n",
       "       [4.8, 3.4, 1.9, 0.2],\n",
       "       [5. , 3. , 1.6, 0.2],\n",
       "       [5. , 3.4, 1.6, 0.4],\n",
       "       [5.2, 3.5, 1.5, 0.2],\n",
       "       [5.2, 3.4, 1.4, 0.2],\n",
       "       [4.7, 3.2, 1.6, 0.2],\n",
       "       [4.8, 3.1, 1.6, 0.2],\n",
       "       [5.4, 3.4, 1.5, 0.4],\n",
       "       [5.2, 4.1, 1.5, 0.1],\n",
       "       [5.5, 4.2, 1.4, 0.2],\n",
       "       [4.9, 3.1, 1.5, 0.1],\n",
       "       [5. , 3.2, 1.2, 0.2],\n",
       "       [5.5, 3.5, 1.3, 0.2],\n",
       "       [4.9, 3.1, 1.5, 0.1],\n",
       "       [4.4, 3. , 1.3, 0.2],\n",
       "       [5.1, 3.4, 1.5, 0.2],\n",
       "       [5. , 3.5, 1.3, 0.3],\n",
       "       [4.5, 2.3, 1.3, 0.3],\n",
       "       [4.4, 3.2, 1.3, 0.2],\n",
       "       [5. , 3.5, 1.6, 0.6],\n",
       "       [5.1, 3.8, 1.9, 0.4],\n",
       "       [4.8, 3. , 1.4, 0.3],\n",
       "       [5.1, 3.8, 1.6, 0.2],\n",
       "       [4.6, 3.2, 1.4, 0.2],\n",
       "       [5.3, 3.7, 1.5, 0.2],\n",
       "       [5. , 3.3, 1.4, 0.2],\n",
       "       [7. , 3.2, 4.7, 1.4],\n",
       "       [6.4, 3.2, 4.5, 1.5],\n",
       "       [6.9, 3.1, 4.9, 1.5],\n",
       "       [5.5, 2.3, 4. , 1.3],\n",
       "       [6.5, 2.8, 4.6, 1.5],\n",
       "       [5.7, 2.8, 4.5, 1.3],\n",
       "       [6.3, 3.3, 4.7, 1.6],\n",
       "       [4.9, 2.4, 3.3, 1. ],\n",
       "       [6.6, 2.9, 4.6, 1.3],\n",
       "       [5.2, 2.7, 3.9, 1.4],\n",
       "       [5. , 2. , 3.5, 1. ],\n",
       "       [5.9, 3. , 4.2, 1.5],\n",
       "       [6. , 2.2, 4. , 1. ],\n",
       "       [6.1, 2.9, 4.7, 1.4],\n",
       "       [5.6, 2.9, 3.6, 1.3],\n",
       "       [6.7, 3.1, 4.4, 1.4],\n",
       "       [5.6, 3. , 4.5, 1.5],\n",
       "       [5.8, 2.7, 4.1, 1. ],\n",
       "       [6.2, 2.2, 4.5, 1.5],\n",
       "       [5.6, 2.5, 3.9, 1.1],\n",
       "       [5.9, 3.2, 4.8, 1.8],\n",
       "       [6.1, 2.8, 4. , 1.3],\n",
       "       [6.3, 2.5, 4.9, 1.5],\n",
       "       [6.1, 2.8, 4.7, 1.2],\n",
       "       [6.4, 2.9, 4.3, 1.3],\n",
       "       [6.6, 3. , 4.4, 1.4],\n",
       "       [6.8, 2.8, 4.8, 1.4],\n",
       "       [6.7, 3. , 5. , 1.7],\n",
       "       [6. , 2.9, 4.5, 1.5],\n",
       "       [5.7, 2.6, 3.5, 1. ],\n",
       "       [5.5, 2.4, 3.8, 1.1],\n",
       "       [5.5, 2.4, 3.7, 1. ],\n",
       "       [5.8, 2.7, 3.9, 1.2],\n",
       "       [6. , 2.7, 5.1, 1.6],\n",
       "       [5.4, 3. , 4.5, 1.5],\n",
       "       [6. , 3.4, 4.5, 1.6],\n",
       "       [6.7, 3.1, 4.7, 1.5],\n",
       "       [6.3, 2.3, 4.4, 1.3],\n",
       "       [5.6, 3. , 4.1, 1.3],\n",
       "       [5.5, 2.5, 4. , 1.3],\n",
       "       [5.5, 2.6, 4.4, 1.2],\n",
       "       [6.1, 3. , 4.6, 1.4],\n",
       "       [5.8, 2.6, 4. , 1.2],\n",
       "       [5. , 2.3, 3.3, 1. ],\n",
       "       [5.6, 2.7, 4.2, 1.3],\n",
       "       [5.7, 3. , 4.2, 1.2],\n",
       "       [5.7, 2.9, 4.2, 1.3],\n",
       "       [6.2, 2.9, 4.3, 1.3],\n",
       "       [5.1, 2.5, 3. , 1.1],\n",
       "       [5.7, 2.8, 4.1, 1.3],\n",
       "       [6.3, 3.3, 6. , 2.5],\n",
       "       [5.8, 2.7, 5.1, 1.9],\n",
       "       [7.1, 3. , 5.9, 2.1],\n",
       "       [6.3, 2.9, 5.6, 1.8],\n",
       "       [6.5, 3. , 5.8, 2.2],\n",
       "       [7.6, 3. , 6.6, 2.1],\n",
       "       [4.9, 2.5, 4.5, 1.7],\n",
       "       [7.3, 2.9, 6.3, 1.8],\n",
       "       [6.7, 2.5, 5.8, 1.8],\n",
       "       [7.2, 3.6, 6.1, 2.5],\n",
       "       [6.5, 3.2, 5.1, 2. ],\n",
       "       [6.4, 2.7, 5.3, 1.9],\n",
       "       [6.8, 3. , 5.5, 2.1],\n",
       "       [5.7, 2.5, 5. , 2. ],\n",
       "       [5.8, 2.8, 5.1, 2.4],\n",
       "       [6.4, 3.2, 5.3, 2.3],\n",
       "       [6.5, 3. , 5.5, 1.8],\n",
       "       [7.7, 3.8, 6.7, 2.2],\n",
       "       [7.7, 2.6, 6.9, 2.3],\n",
       "       [6. , 2.2, 5. , 1.5],\n",
       "       [6.9, 3.2, 5.7, 2.3],\n",
       "       [5.6, 2.8, 4.9, 2. ],\n",
       "       [7.7, 2.8, 6.7, 2. ],\n",
       "       [6.3, 2.7, 4.9, 1.8],\n",
       "       [6.7, 3.3, 5.7, 2.1],\n",
       "       [7.2, 3.2, 6. , 1.8],\n",
       "       [6.2, 2.8, 4.8, 1.8],\n",
       "       [6.1, 3. , 4.9, 1.8],\n",
       "       [6.4, 2.8, 5.6, 2.1],\n",
       "       [7.2, 3. , 5.8, 1.6],\n",
       "       [7.4, 2.8, 6.1, 1.9],\n",
       "       [7.9, 3.8, 6.4, 2. ],\n",
       "       [6.4, 2.8, 5.6, 2.2],\n",
       "       [6.3, 2.8, 5.1, 1.5],\n",
       "       [6.1, 2.6, 5.6, 1.4],\n",
       "       [7.7, 3. , 6.1, 2.3],\n",
       "       [6.3, 3.4, 5.6, 2.4],\n",
       "       [6.4, 3.1, 5.5, 1.8],\n",
       "       [6. , 3. , 4.8, 1.8],\n",
       "       [6.9, 3.1, 5.4, 2.1],\n",
       "       [6.7, 3.1, 5.6, 2.4],\n",
       "       [6.9, 3.1, 5.1, 2.3],\n",
       "       [5.8, 2.7, 5.1, 1.9],\n",
       "       [6.8, 3.2, 5.9, 2.3],\n",
       "       [6.7, 3.3, 5.7, 2.5],\n",
       "       [6.7, 3. , 5.2, 2.3],\n",
       "       [6.3, 2.5, 5. , 1.9],\n",
       "       [6.5, 3. , 5.2, 2. ],\n",
       "       [6.2, 3.4, 5.4, 2.3],\n",
       "       [5.9, 3. , 5.1, 1.8]])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "iris.data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-07-07T12:07:56.653638Z",
     "start_time": "2018-07-07T12:07:56.645640Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(150, 4)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "iris.data.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-07-07T12:08:33.821099Z",
     "start_time": "2018-07-07T12:08:33.811106Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
      " 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
      " 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2\n",
      " 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\n",
      " 2 2]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(150,)"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print(iris.target)\n",
    "iris.target.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-07-07T12:08:54.252627Z",
     "start_time": "2018-07-07T12:08:54.244636Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['setosa', 'versicolor', 'virginica'], dtype='<U10')"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "iris.target_names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-07-07T12:16:47.076423Z",
     "start_time": "2018-07-07T12:16:47.037448Z"
    },
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts': '/nbextensions/echarts/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "    <div id=\"e2b1d3b0eff549cd91b6b551d2baa78b\" style=\"width:800px;height:400px;\"></div>\n",
       "\n",
       "\n",
       "<script>\n",
       "    require(['echarts'], function(echarts) {\n",
       "        \n",
       "var myChart_e2b1d3b0eff549cd91b6b551d2baa78b = echarts.init(document.getElementById('e2b1d3b0eff549cd91b6b551d2baa78b'), 'light', {renderer: 'canvas'});\n",
       "\n",
       "var option_e2b1d3b0eff549cd91b6b551d2baa78b = {\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u4e3b\\u6807\\u9898\",\n",
       "            \"subtext\": \"\\u526f\\u6807\\u9898\",\n",
       "            \"left\": \"auto\",\n",
       "            \"top\": \"auto\",\n",
       "            \"textStyle\": {\n",
       "                \"fontSize\": 18\n",
       "            },\n",
       "            \"subtextStyle\": {\n",
       "                \"fontSize\": 12\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"toolbox\": {\n",
       "        \"show\": true,\n",
       "        \"orient\": \"vertical\",\n",
       "        \"left\": \"95%\",\n",
       "        \"top\": \"center\",\n",
       "        \"feature\": {\n",
       "            \"saveAsImage\": {\n",
       "                \"show\": true,\n",
       "                \"title\": \"\\u4e0b\\u8f7d\\u56fe\\u7247\"\n",
       "            },\n",
       "            \"restore\": {\n",
       "                \"show\": true\n",
       "            },\n",
       "            \"dataView\": {\n",
       "                \"show\": true\n",
       "            }\n",
       "        }\n",
       "    },\n",
       "    \"series_id\": 2213666,\n",
       "    \"tooltip\": {\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"backgroundColor\": \"rgba(50,50,50,0.7)\",\n",
       "        \"borderColor\": \"#333\",\n",
       "        \"borderWidth\": 0\n",
       "    },\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"scatter\",\n",
       "            \"name\": \"first\",\n",
       "            \"symbol\": \"circle\",\n",
       "            \"symbolSize\": 10,\n",
       "            \"data\": [\n",
       "                [\n",
       "                    5.1,\n",
       "                    3.5\n",
       "                ],\n",
       "                [\n",
       "                    4.9,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    4.7,\n",
       "                    3.2\n",
       "                ],\n",
       "                [\n",
       "                    4.6,\n",
       "                    3.1\n",
       "                ],\n",
       "                [\n",
       "                    5.0,\n",
       "                    3.6\n",
       "                ],\n",
       "                [\n",
       "                    5.4,\n",
       "                    3.9\n",
       "                ],\n",
       "                [\n",
       "                    4.6,\n",
       "                    3.4\n",
       "                ],\n",
       "                [\n",
       "                    5.0,\n",
       "                    3.4\n",
       "                ],\n",
       "                [\n",
       "                    4.4,\n",
       "                    2.9\n",
       "                ],\n",
       "                [\n",
       "                    4.9,\n",
       "                    3.1\n",
       "                ],\n",
       "                [\n",
       "                    5.4,\n",
       "                    3.7\n",
       "                ],\n",
       "                [\n",
       "                    4.8,\n",
       "                    3.4\n",
       "                ],\n",
       "                [\n",
       "                    4.8,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    4.3,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    5.8,\n",
       "                    4.0\n",
       "                ],\n",
       "                [\n",
       "                    5.7,\n",
       "                    4.4\n",
       "                ],\n",
       "                [\n",
       "                    5.4,\n",
       "                    3.9\n",
       "                ],\n",
       "                [\n",
       "                    5.1,\n",
       "                    3.5\n",
       "                ],\n",
       "                [\n",
       "                    5.7,\n",
       "                    3.8\n",
       "                ],\n",
       "                [\n",
       "                    5.1,\n",
       "                    3.8\n",
       "                ],\n",
       "                [\n",
       "                    5.4,\n",
       "                    3.4\n",
       "                ],\n",
       "                [\n",
       "                    5.1,\n",
       "                    3.7\n",
       "                ],\n",
       "                [\n",
       "                    4.6,\n",
       "                    3.6\n",
       "                ],\n",
       "                [\n",
       "                    5.1,\n",
       "                    3.3\n",
       "                ],\n",
       "                [\n",
       "                    4.8,\n",
       "                    3.4\n",
       "                ],\n",
       "                [\n",
       "                    5.0,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    5.0,\n",
       "                    3.4\n",
       "                ],\n",
       "                [\n",
       "                    5.2,\n",
       "                    3.5\n",
       "                ],\n",
       "                [\n",
       "                    5.2,\n",
       "                    3.4\n",
       "                ],\n",
       "                [\n",
       "                    4.7,\n",
       "                    3.2\n",
       "                ],\n",
       "                [\n",
       "                    4.8,\n",
       "                    3.1\n",
       "                ],\n",
       "                [\n",
       "                    5.4,\n",
       "                    3.4\n",
       "                ],\n",
       "                [\n",
       "                    5.2,\n",
       "                    4.1\n",
       "                ],\n",
       "                [\n",
       "                    5.5,\n",
       "                    4.2\n",
       "                ],\n",
       "                [\n",
       "                    4.9,\n",
       "                    3.1\n",
       "                ],\n",
       "                [\n",
       "                    5.0,\n",
       "                    3.2\n",
       "                ],\n",
       "                [\n",
       "                    5.5,\n",
       "                    3.5\n",
       "                ],\n",
       "                [\n",
       "                    4.9,\n",
       "                    3.1\n",
       "                ],\n",
       "                [\n",
       "                    4.4,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    5.1,\n",
       "                    3.4\n",
       "                ],\n",
       "                [\n",
       "                    5.0,\n",
       "                    3.5\n",
       "                ],\n",
       "                [\n",
       "                    4.5,\n",
       "                    2.3\n",
       "                ],\n",
       "                [\n",
       "                    4.4,\n",
       "                    3.2\n",
       "                ],\n",
       "                [\n",
       "                    5.0,\n",
       "                    3.5\n",
       "                ],\n",
       "                [\n",
       "                    5.1,\n",
       "                    3.8\n",
       "                ],\n",
       "                [\n",
       "                    4.8,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    5.1,\n",
       "                    3.8\n",
       "                ],\n",
       "                [\n",
       "                    4.6,\n",
       "                    3.2\n",
       "                ],\n",
       "                [\n",
       "                    5.3,\n",
       "                    3.7\n",
       "                ],\n",
       "                [\n",
       "                    5.0,\n",
       "                    3.3\n",
       "                ],\n",
       "                [\n",
       "                    7.0,\n",
       "                    3.2\n",
       "                ],\n",
       "                [\n",
       "                    6.4,\n",
       "                    3.2\n",
       "                ],\n",
       "                [\n",
       "                    6.9,\n",
       "                    3.1\n",
       "                ],\n",
       "                [\n",
       "                    5.5,\n",
       "                    2.3\n",
       "                ],\n",
       "                [\n",
       "                    6.5,\n",
       "                    2.8\n",
       "                ],\n",
       "                [\n",
       "                    5.7,\n",
       "                    2.8\n",
       "                ],\n",
       "                [\n",
       "                    6.3,\n",
       "                    3.3\n",
       "                ],\n",
       "                [\n",
       "                    4.9,\n",
       "                    2.4\n",
       "                ],\n",
       "                [\n",
       "                    6.6,\n",
       "                    2.9\n",
       "                ],\n",
       "                [\n",
       "                    5.2,\n",
       "                    2.7\n",
       "                ],\n",
       "                [\n",
       "                    5.0,\n",
       "                    2.0\n",
       "                ],\n",
       "                [\n",
       "                    5.9,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    6.0,\n",
       "                    2.2\n",
       "                ],\n",
       "                [\n",
       "                    6.1,\n",
       "                    2.9\n",
       "                ],\n",
       "                [\n",
       "                    5.6,\n",
       "                    2.9\n",
       "                ],\n",
       "                [\n",
       "                    6.7,\n",
       "                    3.1\n",
       "                ],\n",
       "                [\n",
       "                    5.6,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    5.8,\n",
       "                    2.7\n",
       "                ],\n",
       "                [\n",
       "                    6.2,\n",
       "                    2.2\n",
       "                ],\n",
       "                [\n",
       "                    5.6,\n",
       "                    2.5\n",
       "                ],\n",
       "                [\n",
       "                    5.9,\n",
       "                    3.2\n",
       "                ],\n",
       "                [\n",
       "                    6.1,\n",
       "                    2.8\n",
       "                ],\n",
       "                [\n",
       "                    6.3,\n",
       "                    2.5\n",
       "                ],\n",
       "                [\n",
       "                    6.1,\n",
       "                    2.8\n",
       "                ],\n",
       "                [\n",
       "                    6.4,\n",
       "                    2.9\n",
       "                ],\n",
       "                [\n",
       "                    6.6,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    6.8,\n",
       "                    2.8\n",
       "                ],\n",
       "                [\n",
       "                    6.7,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    6.0,\n",
       "                    2.9\n",
       "                ],\n",
       "                [\n",
       "                    5.7,\n",
       "                    2.6\n",
       "                ],\n",
       "                [\n",
       "                    5.5,\n",
       "                    2.4\n",
       "                ],\n",
       "                [\n",
       "                    5.5,\n",
       "                    2.4\n",
       "                ],\n",
       "                [\n",
       "                    5.8,\n",
       "                    2.7\n",
       "                ],\n",
       "                [\n",
       "                    6.0,\n",
       "                    2.7\n",
       "                ],\n",
       "                [\n",
       "                    5.4,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    6.0,\n",
       "                    3.4\n",
       "                ],\n",
       "                [\n",
       "                    6.7,\n",
       "                    3.1\n",
       "                ],\n",
       "                [\n",
       "                    6.3,\n",
       "                    2.3\n",
       "                ],\n",
       "                [\n",
       "                    5.6,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    5.5,\n",
       "                    2.5\n",
       "                ],\n",
       "                [\n",
       "                    5.5,\n",
       "                    2.6\n",
       "                ],\n",
       "                [\n",
       "                    6.1,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    5.8,\n",
       "                    2.6\n",
       "                ],\n",
       "                [\n",
       "                    5.0,\n",
       "                    2.3\n",
       "                ],\n",
       "                [\n",
       "                    5.6,\n",
       "                    2.7\n",
       "                ],\n",
       "                [\n",
       "                    5.7,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    5.7,\n",
       "                    2.9\n",
       "                ],\n",
       "                [\n",
       "                    6.2,\n",
       "                    2.9\n",
       "                ],\n",
       "                [\n",
       "                    5.1,\n",
       "                    2.5\n",
       "                ],\n",
       "                [\n",
       "                    5.7,\n",
       "                    2.8\n",
       "                ],\n",
       "                [\n",
       "                    6.3,\n",
       "                    3.3\n",
       "                ],\n",
       "                [\n",
       "                    5.8,\n",
       "                    2.7\n",
       "                ],\n",
       "                [\n",
       "                    7.1,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    6.3,\n",
       "                    2.9\n",
       "                ],\n",
       "                [\n",
       "                    6.5,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    7.6,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    4.9,\n",
       "                    2.5\n",
       "                ],\n",
       "                [\n",
       "                    7.3,\n",
       "                    2.9\n",
       "                ],\n",
       "                [\n",
       "                    6.7,\n",
       "                    2.5\n",
       "                ],\n",
       "                [\n",
       "                    7.2,\n",
       "                    3.6\n",
       "                ],\n",
       "                [\n",
       "                    6.5,\n",
       "                    3.2\n",
       "                ],\n",
       "                [\n",
       "                    6.4,\n",
       "                    2.7\n",
       "                ],\n",
       "                [\n",
       "                    6.8,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    5.7,\n",
       "                    2.5\n",
       "                ],\n",
       "                [\n",
       "                    5.8,\n",
       "                    2.8\n",
       "                ],\n",
       "                [\n",
       "                    6.4,\n",
       "                    3.2\n",
       "                ],\n",
       "                [\n",
       "                    6.5,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    7.7,\n",
       "                    3.8\n",
       "                ],\n",
       "                [\n",
       "                    7.7,\n",
       "                    2.6\n",
       "                ],\n",
       "                [\n",
       "                    6.0,\n",
       "                    2.2\n",
       "                ],\n",
       "                [\n",
       "                    6.9,\n",
       "                    3.2\n",
       "                ],\n",
       "                [\n",
       "                    5.6,\n",
       "                    2.8\n",
       "                ],\n",
       "                [\n",
       "                    7.7,\n",
       "                    2.8\n",
       "                ],\n",
       "                [\n",
       "                    6.3,\n",
       "                    2.7\n",
       "                ],\n",
       "                [\n",
       "                    6.7,\n",
       "                    3.3\n",
       "                ],\n",
       "                [\n",
       "                    7.2,\n",
       "                    3.2\n",
       "                ],\n",
       "                [\n",
       "                    6.2,\n",
       "                    2.8\n",
       "                ],\n",
       "                [\n",
       "                    6.1,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    6.4,\n",
       "                    2.8\n",
       "                ],\n",
       "                [\n",
       "                    7.2,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    7.4,\n",
       "                    2.8\n",
       "                ],\n",
       "                [\n",
       "                    7.9,\n",
       "                    3.8\n",
       "                ],\n",
       "                [\n",
       "                    6.4,\n",
       "                    2.8\n",
       "                ],\n",
       "                [\n",
       "                    6.3,\n",
       "                    2.8\n",
       "                ],\n",
       "                [\n",
       "                    6.1,\n",
       "                    2.6\n",
       "                ],\n",
       "                [\n",
       "                    7.7,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    6.3,\n",
       "                    3.4\n",
       "                ],\n",
       "                [\n",
       "                    6.4,\n",
       "                    3.1\n",
       "                ],\n",
       "                [\n",
       "                    6.0,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    6.9,\n",
       "                    3.1\n",
       "                ],\n",
       "                [\n",
       "                    6.7,\n",
       "                    3.1\n",
       "                ],\n",
       "                [\n",
       "                    6.9,\n",
       "                    3.1\n",
       "                ],\n",
       "                [\n",
       "                    5.8,\n",
       "                    2.7\n",
       "                ],\n",
       "                [\n",
       "                    6.8,\n",
       "                    3.2\n",
       "                ],\n",
       "                [\n",
       "                    6.7,\n",
       "                    3.3\n",
       "                ],\n",
       "                [\n",
       "                    6.7,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    6.3,\n",
       "                    2.5\n",
       "                ],\n",
       "                [\n",
       "                    6.5,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    6.2,\n",
       "                    3.4\n",
       "                ],\n",
       "                [\n",
       "                    5.9,\n",
       "                    3.0\n",
       "                ]\n",
       "            ],\n",
       "            \"label\": {\n",
       "                \"normal\": {\n",
       "                    \"show\": false,\n",
       "                    \"position\": \"top\",\n",
       "                    \"textStyle\": {\n",
       "                        \"fontSize\": 12\n",
       "                    }\n",
       "                },\n",
       "                \"emphasis\": {\n",
       "                    \"show\": true,\n",
       "                    \"textStyle\": {\n",
       "                        \"fontSize\": 12\n",
       "                    }\n",
       "                }\n",
       "            },\n",
       "            \"markPoint\": {\n",
       "                \"data\": []\n",
       "            },\n",
       "            \"markLine\": {\n",
       "                \"data\": []\n",
       "            },\n",
       "            \"seriesId\": 2213666\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"first\"\n",
       "            ],\n",
       "            \"selectedMode\": \"multiple\",\n",
       "            \"show\": true,\n",
       "            \"left\": \"center\",\n",
       "            \"top\": \"top\",\n",
       "            \"orient\": \"horizontal\",\n",
       "            \"textStyle\": {\n",
       "                \"fontSize\": 12\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"xAxis\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"nameLocation\": \"middle\",\n",
       "            \"nameGap\": 25,\n",
       "            \"nameTextStyle\": {\n",
       "                \"fontSize\": 14\n",
       "            },\n",
       "            \"axisTick\": {\n",
       "                \"alignWithLabel\": false\n",
       "            },\n",
       "            \"inverse\": false,\n",
       "            \"boundaryGap\": true,\n",
       "            \"type\": \"value\",\n",
       "            \"splitLine\": {\n",
       "                \"show\": true\n",
       "            },\n",
       "            \"axisLabel\": {\n",
       "                \"interval\": \"auto\",\n",
       "                \"rotate\": 0,\n",
       "                \"margin\": 8,\n",
       "                \"textStyle\": {\n",
       "                    \"fontSize\": 12\n",
       "                }\n",
       "            },\n",
       "            \"data\": [\n",
       "                5.1,\n",
       "                4.9,\n",
       "                4.7,\n",
       "                4.6,\n",
       "                5.0,\n",
       "                5.4,\n",
       "                4.6,\n",
       "                5.0,\n",
       "                4.4,\n",
       "                4.9,\n",
       "                5.4,\n",
       "                4.8,\n",
       "                4.8,\n",
       "                4.3,\n",
       "                5.8,\n",
       "                5.7,\n",
       "                5.4,\n",
       "                5.1,\n",
       "                5.7,\n",
       "                5.1,\n",
       "                5.4,\n",
       "                5.1,\n",
       "                4.6,\n",
       "                5.1,\n",
       "                4.8,\n",
       "                5.0,\n",
       "                5.0,\n",
       "                5.2,\n",
       "                5.2,\n",
       "                4.7,\n",
       "                4.8,\n",
       "                5.4,\n",
       "                5.2,\n",
       "                5.5,\n",
       "                4.9,\n",
       "                5.0,\n",
       "                5.5,\n",
       "                4.9,\n",
       "                4.4,\n",
       "                5.1,\n",
       "                5.0,\n",
       "                4.5,\n",
       "                4.4,\n",
       "                5.0,\n",
       "                5.1,\n",
       "                4.8,\n",
       "                5.1,\n",
       "                4.6,\n",
       "                5.3,\n",
       "                5.0,\n",
       "                7.0,\n",
       "                6.4,\n",
       "                6.9,\n",
       "                5.5,\n",
       "                6.5,\n",
       "                5.7,\n",
       "                6.3,\n",
       "                4.9,\n",
       "                6.6,\n",
       "                5.2,\n",
       "                5.0,\n",
       "                5.9,\n",
       "                6.0,\n",
       "                6.1,\n",
       "                5.6,\n",
       "                6.7,\n",
       "                5.6,\n",
       "                5.8,\n",
       "                6.2,\n",
       "                5.6,\n",
       "                5.9,\n",
       "                6.1,\n",
       "                6.3,\n",
       "                6.1,\n",
       "                6.4,\n",
       "                6.6,\n",
       "                6.8,\n",
       "                6.7,\n",
       "                6.0,\n",
       "                5.7,\n",
       "                5.5,\n",
       "                5.5,\n",
       "                5.8,\n",
       "                6.0,\n",
       "                5.4,\n",
       "                6.0,\n",
       "                6.7,\n",
       "                6.3,\n",
       "                5.6,\n",
       "                5.5,\n",
       "                5.5,\n",
       "                6.1,\n",
       "                5.8,\n",
       "                5.0,\n",
       "                5.6,\n",
       "                5.7,\n",
       "                5.7,\n",
       "                6.2,\n",
       "                5.1,\n",
       "                5.7,\n",
       "                6.3,\n",
       "                5.8,\n",
       "                7.1,\n",
       "                6.3,\n",
       "                6.5,\n",
       "                7.6,\n",
       "                4.9,\n",
       "                7.3,\n",
       "                6.7,\n",
       "                7.2,\n",
       "                6.5,\n",
       "                6.4,\n",
       "                6.8,\n",
       "                5.7,\n",
       "                5.8,\n",
       "                6.4,\n",
       "                6.5,\n",
       "                7.7,\n",
       "                7.7,\n",
       "                6.0,\n",
       "                6.9,\n",
       "                5.6,\n",
       "                7.7,\n",
       "                6.3,\n",
       "                6.7,\n",
       "                7.2,\n",
       "                6.2,\n",
       "                6.1,\n",
       "                6.4,\n",
       "                7.2,\n",
       "                7.4,\n",
       "                7.9,\n",
       "                6.4,\n",
       "                6.3,\n",
       "                6.1,\n",
       "                7.7,\n",
       "                6.3,\n",
       "                6.4,\n",
       "                6.0,\n",
       "                6.9,\n",
       "                6.7,\n",
       "                6.9,\n",
       "                5.8,\n",
       "                6.8,\n",
       "                6.7,\n",
       "                6.7,\n",
       "                6.3,\n",
       "                6.5,\n",
       "                6.2,\n",
       "                5.9\n",
       "            ]\n",
       "        }\n",
       "    ],\n",
       "    \"yAxis\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"nameLocation\": \"middle\",\n",
       "            \"nameGap\": 25,\n",
       "            \"nameTextStyle\": {\n",
       "                \"fontSize\": 14\n",
       "            },\n",
       "            \"axisTick\": {\n",
       "                \"alignWithLabel\": false\n",
       "            },\n",
       "            \"inverse\": false,\n",
       "            \"boundaryGap\": true,\n",
       "            \"type\": \"value\",\n",
       "            \"splitLine\": {\n",
       "                \"show\": true\n",
       "            },\n",
       "            \"axisLabel\": {\n",
       "                \"interval\": \"auto\",\n",
       "                \"formatter\": \"{value} \",\n",
       "                \"rotate\": 0,\n",
       "                \"margin\": 8,\n",
       "                \"textStyle\": {\n",
       "                    \"fontSize\": 12\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\",\n",
       "        \"#f6f5ec\"\n",
       "    ]\n",
       "};\n",
       "myChart_e2b1d3b0eff549cd91b6b551d2baa78b.setOption(option_e2b1d3b0eff549cd91b6b551d2baa78b);\n",
       "\n",
       "    });\n",
       "</script>\n"
      ],
      "text/plain": [
       "<pyecharts.charts.scatter.Scatter at 0x17c6ba39d68>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "scatter = Scatter('主标题', '副标题')\n",
    "scatter.add('first', iris.data[:,0], iris.data[:,1])\n",
    "scatter"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-07-07T12:28:51.926968Z",
     "start_time": "2018-07-07T12:28:51.889984Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts': '/nbextensions/echarts/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "    <div id=\"640a54445ebb4318b5e9cebf0750b374\" style=\"width:800px;height:400px;\"></div>\n",
       "\n",
       "\n",
       "<script>\n",
       "    require(['echarts'], function(echarts) {\n",
       "        \n",
       "var myChart_640a54445ebb4318b5e9cebf0750b374 = echarts.init(document.getElementById('640a54445ebb4318b5e9cebf0750b374'), 'light', {renderer: 'canvas'});\n",
       "\n",
       "var option_640a54445ebb4318b5e9cebf0750b374 = {\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u4e3b\\u6807\\u9898\",\n",
       "            \"subtext\": \"\\u526f\\u6807\\u9898\",\n",
       "            \"left\": \"auto\",\n",
       "            \"top\": \"auto\",\n",
       "            \"textStyle\": {\n",
       "                \"fontSize\": 18\n",
       "            },\n",
       "            \"subtextStyle\": {\n",
       "                \"fontSize\": 12\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"toolbox\": {\n",
       "        \"show\": true,\n",
       "        \"orient\": \"vertical\",\n",
       "        \"left\": \"95%\",\n",
       "        \"top\": \"center\",\n",
       "        \"feature\": {\n",
       "            \"saveAsImage\": {\n",
       "                \"show\": true,\n",
       "                \"title\": \"\\u4e0b\\u8f7d\\u56fe\\u7247\"\n",
       "            },\n",
       "            \"restore\": {\n",
       "                \"show\": true\n",
       "            },\n",
       "            \"dataView\": {\n",
       "                \"show\": true\n",
       "            }\n",
       "        }\n",
       "    },\n",
       "    \"series_id\": 5082442,\n",
       "    \"tooltip\": {\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"backgroundColor\": \"rgba(50,50,50,0.7)\",\n",
       "        \"borderColor\": \"#333\",\n",
       "        \"borderWidth\": 0\n",
       "    },\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"scatter\",\n",
       "            \"name\": \"first\",\n",
       "            \"symbol\": \"circle\",\n",
       "            \"symbolSize\": 10,\n",
       "            \"data\": [\n",
       "                [\n",
       "                    5.1,\n",
       "                    3.5\n",
       "                ],\n",
       "                [\n",
       "                    4.9,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    4.7,\n",
       "                    3.2\n",
       "                ],\n",
       "                [\n",
       "                    4.6,\n",
       "                    3.1\n",
       "                ],\n",
       "                [\n",
       "                    5.0,\n",
       "                    3.6\n",
       "                ],\n",
       "                [\n",
       "                    5.4,\n",
       "                    3.9\n",
       "                ],\n",
       "                [\n",
       "                    4.6,\n",
       "                    3.4\n",
       "                ],\n",
       "                [\n",
       "                    5.0,\n",
       "                    3.4\n",
       "                ],\n",
       "                [\n",
       "                    4.4,\n",
       "                    2.9\n",
       "                ],\n",
       "                [\n",
       "                    4.9,\n",
       "                    3.1\n",
       "                ],\n",
       "                [\n",
       "                    5.4,\n",
       "                    3.7\n",
       "                ],\n",
       "                [\n",
       "                    4.8,\n",
       "                    3.4\n",
       "                ],\n",
       "                [\n",
       "                    4.8,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    4.3,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    5.8,\n",
       "                    4.0\n",
       "                ],\n",
       "                [\n",
       "                    5.7,\n",
       "                    4.4\n",
       "                ],\n",
       "                [\n",
       "                    5.4,\n",
       "                    3.9\n",
       "                ],\n",
       "                [\n",
       "                    5.1,\n",
       "                    3.5\n",
       "                ],\n",
       "                [\n",
       "                    5.7,\n",
       "                    3.8\n",
       "                ],\n",
       "                [\n",
       "                    5.1,\n",
       "                    3.8\n",
       "                ],\n",
       "                [\n",
       "                    5.4,\n",
       "                    3.4\n",
       "                ],\n",
       "                [\n",
       "                    5.1,\n",
       "                    3.7\n",
       "                ],\n",
       "                [\n",
       "                    4.6,\n",
       "                    3.6\n",
       "                ],\n",
       "                [\n",
       "                    5.1,\n",
       "                    3.3\n",
       "                ],\n",
       "                [\n",
       "                    4.8,\n",
       "                    3.4\n",
       "                ],\n",
       "                [\n",
       "                    5.0,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    5.0,\n",
       "                    3.4\n",
       "                ],\n",
       "                [\n",
       "                    5.2,\n",
       "                    3.5\n",
       "                ],\n",
       "                [\n",
       "                    5.2,\n",
       "                    3.4\n",
       "                ],\n",
       "                [\n",
       "                    4.7,\n",
       "                    3.2\n",
       "                ],\n",
       "                [\n",
       "                    4.8,\n",
       "                    3.1\n",
       "                ],\n",
       "                [\n",
       "                    5.4,\n",
       "                    3.4\n",
       "                ],\n",
       "                [\n",
       "                    5.2,\n",
       "                    4.1\n",
       "                ],\n",
       "                [\n",
       "                    5.5,\n",
       "                    4.2\n",
       "                ],\n",
       "                [\n",
       "                    4.9,\n",
       "                    3.1\n",
       "                ],\n",
       "                [\n",
       "                    5.0,\n",
       "                    3.2\n",
       "                ],\n",
       "                [\n",
       "                    5.5,\n",
       "                    3.5\n",
       "                ],\n",
       "                [\n",
       "                    4.9,\n",
       "                    3.1\n",
       "                ],\n",
       "                [\n",
       "                    4.4,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    5.1,\n",
       "                    3.4\n",
       "                ],\n",
       "                [\n",
       "                    5.0,\n",
       "                    3.5\n",
       "                ],\n",
       "                [\n",
       "                    4.5,\n",
       "                    2.3\n",
       "                ],\n",
       "                [\n",
       "                    4.4,\n",
       "                    3.2\n",
       "                ],\n",
       "                [\n",
       "                    5.0,\n",
       "                    3.5\n",
       "                ],\n",
       "                [\n",
       "                    5.1,\n",
       "                    3.8\n",
       "                ],\n",
       "                [\n",
       "                    4.8,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    5.1,\n",
       "                    3.8\n",
       "                ],\n",
       "                [\n",
       "                    4.6,\n",
       "                    3.2\n",
       "                ],\n",
       "                [\n",
       "                    5.3,\n",
       "                    3.7\n",
       "                ],\n",
       "                [\n",
       "                    5.0,\n",
       "                    3.3\n",
       "                ]\n",
       "            ],\n",
       "            \"label\": {\n",
       "                \"normal\": {\n",
       "                    \"show\": false,\n",
       "                    \"position\": \"top\",\n",
       "                    \"textStyle\": {\n",
       "                        \"fontSize\": 12\n",
       "                    }\n",
       "                },\n",
       "                \"emphasis\": {\n",
       "                    \"show\": true,\n",
       "                    \"textStyle\": {\n",
       "                        \"fontSize\": 12\n",
       "                    }\n",
       "                }\n",
       "            },\n",
       "            \"markPoint\": {\n",
       "                \"data\": []\n",
       "            },\n",
       "            \"markLine\": {\n",
       "                \"data\": []\n",
       "            },\n",
       "            \"seriesId\": 5082442\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"scatter\",\n",
       "            \"name\": \"second\",\n",
       "            \"symbol\": \"circle\",\n",
       "            \"symbolSize\": 10,\n",
       "            \"data\": [\n",
       "                [\n",
       "                    7.0,\n",
       "                    3.2\n",
       "                ],\n",
       "                [\n",
       "                    6.4,\n",
       "                    3.2\n",
       "                ],\n",
       "                [\n",
       "                    6.9,\n",
       "                    3.1\n",
       "                ],\n",
       "                [\n",
       "                    5.5,\n",
       "                    2.3\n",
       "                ],\n",
       "                [\n",
       "                    6.5,\n",
       "                    2.8\n",
       "                ],\n",
       "                [\n",
       "                    5.7,\n",
       "                    2.8\n",
       "                ],\n",
       "                [\n",
       "                    6.3,\n",
       "                    3.3\n",
       "                ],\n",
       "                [\n",
       "                    4.9,\n",
       "                    2.4\n",
       "                ],\n",
       "                [\n",
       "                    6.6,\n",
       "                    2.9\n",
       "                ],\n",
       "                [\n",
       "                    5.2,\n",
       "                    2.7\n",
       "                ],\n",
       "                [\n",
       "                    5.0,\n",
       "                    2.0\n",
       "                ],\n",
       "                [\n",
       "                    5.9,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    6.0,\n",
       "                    2.2\n",
       "                ],\n",
       "                [\n",
       "                    6.1,\n",
       "                    2.9\n",
       "                ],\n",
       "                [\n",
       "                    5.6,\n",
       "                    2.9\n",
       "                ],\n",
       "                [\n",
       "                    6.7,\n",
       "                    3.1\n",
       "                ],\n",
       "                [\n",
       "                    5.6,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    5.8,\n",
       "                    2.7\n",
       "                ],\n",
       "                [\n",
       "                    6.2,\n",
       "                    2.2\n",
       "                ],\n",
       "                [\n",
       "                    5.6,\n",
       "                    2.5\n",
       "                ],\n",
       "                [\n",
       "                    5.9,\n",
       "                    3.2\n",
       "                ],\n",
       "                [\n",
       "                    6.1,\n",
       "                    2.8\n",
       "                ],\n",
       "                [\n",
       "                    6.3,\n",
       "                    2.5\n",
       "                ],\n",
       "                [\n",
       "                    6.1,\n",
       "                    2.8\n",
       "                ],\n",
       "                [\n",
       "                    6.4,\n",
       "                    2.9\n",
       "                ],\n",
       "                [\n",
       "                    6.6,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    6.8,\n",
       "                    2.8\n",
       "                ],\n",
       "                [\n",
       "                    6.7,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    6.0,\n",
       "                    2.9\n",
       "                ],\n",
       "                [\n",
       "                    5.7,\n",
       "                    2.6\n",
       "                ],\n",
       "                [\n",
       "                    5.5,\n",
       "                    2.4\n",
       "                ],\n",
       "                [\n",
       "                    5.5,\n",
       "                    2.4\n",
       "                ],\n",
       "                [\n",
       "                    5.8,\n",
       "                    2.7\n",
       "                ],\n",
       "                [\n",
       "                    6.0,\n",
       "                    2.7\n",
       "                ],\n",
       "                [\n",
       "                    5.4,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    6.0,\n",
       "                    3.4\n",
       "                ],\n",
       "                [\n",
       "                    6.7,\n",
       "                    3.1\n",
       "                ],\n",
       "                [\n",
       "                    6.3,\n",
       "                    2.3\n",
       "                ],\n",
       "                [\n",
       "                    5.6,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    5.5,\n",
       "                    2.5\n",
       "                ],\n",
       "                [\n",
       "                    5.5,\n",
       "                    2.6\n",
       "                ],\n",
       "                [\n",
       "                    6.1,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    5.8,\n",
       "                    2.6\n",
       "                ],\n",
       "                [\n",
       "                    5.0,\n",
       "                    2.3\n",
       "                ],\n",
       "                [\n",
       "                    5.6,\n",
       "                    2.7\n",
       "                ],\n",
       "                [\n",
       "                    5.7,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    5.7,\n",
       "                    2.9\n",
       "                ],\n",
       "                [\n",
       "                    6.2,\n",
       "                    2.9\n",
       "                ],\n",
       "                [\n",
       "                    5.1,\n",
       "                    2.5\n",
       "                ],\n",
       "                [\n",
       "                    5.7,\n",
       "                    2.8\n",
       "                ]\n",
       "            ],\n",
       "            \"label\": {\n",
       "                \"normal\": {\n",
       "                    \"show\": false,\n",
       "                    \"position\": \"top\",\n",
       "                    \"textStyle\": {\n",
       "                        \"fontSize\": 12\n",
       "                    }\n",
       "                },\n",
       "                \"emphasis\": {\n",
       "                    \"show\": true,\n",
       "                    \"textStyle\": {\n",
       "                        \"fontSize\": 12\n",
       "                    }\n",
       "                }\n",
       "            },\n",
       "            \"markPoint\": {\n",
       "                \"data\": []\n",
       "            },\n",
       "            \"markLine\": {\n",
       "                \"data\": []\n",
       "            },\n",
       "            \"seriesId\": 5082442\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"scatter\",\n",
       "            \"name\": \"third\",\n",
       "            \"symbol\": \"circle\",\n",
       "            \"symbolSize\": 10,\n",
       "            \"data\": [\n",
       "                [\n",
       "                    6.3,\n",
       "                    3.3\n",
       "                ],\n",
       "                [\n",
       "                    5.8,\n",
       "                    2.7\n",
       "                ],\n",
       "                [\n",
       "                    7.1,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    6.3,\n",
       "                    2.9\n",
       "                ],\n",
       "                [\n",
       "                    6.5,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    7.6,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    4.9,\n",
       "                    2.5\n",
       "                ],\n",
       "                [\n",
       "                    7.3,\n",
       "                    2.9\n",
       "                ],\n",
       "                [\n",
       "                    6.7,\n",
       "                    2.5\n",
       "                ],\n",
       "                [\n",
       "                    7.2,\n",
       "                    3.6\n",
       "                ],\n",
       "                [\n",
       "                    6.5,\n",
       "                    3.2\n",
       "                ],\n",
       "                [\n",
       "                    6.4,\n",
       "                    2.7\n",
       "                ],\n",
       "                [\n",
       "                    6.8,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    5.7,\n",
       "                    2.5\n",
       "                ],\n",
       "                [\n",
       "                    5.8,\n",
       "                    2.8\n",
       "                ],\n",
       "                [\n",
       "                    6.4,\n",
       "                    3.2\n",
       "                ],\n",
       "                [\n",
       "                    6.5,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    7.7,\n",
       "                    3.8\n",
       "                ],\n",
       "                [\n",
       "                    7.7,\n",
       "                    2.6\n",
       "                ],\n",
       "                [\n",
       "                    6.0,\n",
       "                    2.2\n",
       "                ],\n",
       "                [\n",
       "                    6.9,\n",
       "                    3.2\n",
       "                ],\n",
       "                [\n",
       "                    5.6,\n",
       "                    2.8\n",
       "                ],\n",
       "                [\n",
       "                    7.7,\n",
       "                    2.8\n",
       "                ],\n",
       "                [\n",
       "                    6.3,\n",
       "                    2.7\n",
       "                ],\n",
       "                [\n",
       "                    6.7,\n",
       "                    3.3\n",
       "                ],\n",
       "                [\n",
       "                    7.2,\n",
       "                    3.2\n",
       "                ],\n",
       "                [\n",
       "                    6.2,\n",
       "                    2.8\n",
       "                ],\n",
       "                [\n",
       "                    6.1,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    6.4,\n",
       "                    2.8\n",
       "                ],\n",
       "                [\n",
       "                    7.2,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    7.4,\n",
       "                    2.8\n",
       "                ],\n",
       "                [\n",
       "                    7.9,\n",
       "                    3.8\n",
       "                ],\n",
       "                [\n",
       "                    6.4,\n",
       "                    2.8\n",
       "                ],\n",
       "                [\n",
       "                    6.3,\n",
       "                    2.8\n",
       "                ],\n",
       "                [\n",
       "                    6.1,\n",
       "                    2.6\n",
       "                ],\n",
       "                [\n",
       "                    7.7,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    6.3,\n",
       "                    3.4\n",
       "                ],\n",
       "                [\n",
       "                    6.4,\n",
       "                    3.1\n",
       "                ],\n",
       "                [\n",
       "                    6.0,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    6.9,\n",
       "                    3.1\n",
       "                ],\n",
       "                [\n",
       "                    6.7,\n",
       "                    3.1\n",
       "                ],\n",
       "                [\n",
       "                    6.9,\n",
       "                    3.1\n",
       "                ],\n",
       "                [\n",
       "                    5.8,\n",
       "                    2.7\n",
       "                ],\n",
       "                [\n",
       "                    6.8,\n",
       "                    3.2\n",
       "                ],\n",
       "                [\n",
       "                    6.7,\n",
       "                    3.3\n",
       "                ],\n",
       "                [\n",
       "                    6.7,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    6.3,\n",
       "                    2.5\n",
       "                ],\n",
       "                [\n",
       "                    6.5,\n",
       "                    3.0\n",
       "                ],\n",
       "                [\n",
       "                    6.2,\n",
       "                    3.4\n",
       "                ],\n",
       "                [\n",
       "                    5.9,\n",
       "                    3.0\n",
       "                ]\n",
       "            ],\n",
       "            \"label\": {\n",
       "                \"normal\": {\n",
       "                    \"show\": false,\n",
       "                    \"position\": \"top\",\n",
       "                    \"textStyle\": {\n",
       "                        \"fontSize\": 12\n",
       "                    }\n",
       "                },\n",
       "                \"emphasis\": {\n",
       "                    \"show\": true,\n",
       "                    \"textStyle\": {\n",
       "                        \"fontSize\": 12\n",
       "                    }\n",
       "                }\n",
       "            },\n",
       "            \"markPoint\": {\n",
       "                \"data\": []\n",
       "            },\n",
       "            \"markLine\": {\n",
       "                \"data\": []\n",
       "            },\n",
       "            \"seriesId\": 5082442\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"first\",\n",
       "                \"second\",\n",
       "                \"third\"\n",
       "            ],\n",
       "            \"selectedMode\": \"multiple\",\n",
       "            \"show\": true,\n",
       "            \"left\": \"center\",\n",
       "            \"top\": \"top\",\n",
       "            \"orient\": \"horizontal\",\n",
       "            \"textStyle\": {\n",
       "                \"fontSize\": 12\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"xAxis\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"nameLocation\": \"middle\",\n",
       "            \"nameGap\": 25,\n",
       "            \"nameTextStyle\": {\n",
       "                \"fontSize\": 14\n",
       "            },\n",
       "            \"axisTick\": {\n",
       "                \"alignWithLabel\": false\n",
       "            },\n",
       "            \"inverse\": false,\n",
       "            \"boundaryGap\": true,\n",
       "            \"type\": \"value\",\n",
       "            \"splitLine\": {\n",
       "                \"show\": true\n",
       "            },\n",
       "            \"axisLabel\": {\n",
       "                \"interval\": \"auto\",\n",
       "                \"rotate\": 0,\n",
       "                \"margin\": 8,\n",
       "                \"textStyle\": {\n",
       "                    \"fontSize\": 12\n",
       "                }\n",
       "            },\n",
       "            \"data\": [\n",
       "                6.3,\n",
       "                5.8,\n",
       "                7.1,\n",
       "                6.3,\n",
       "                6.5,\n",
       "                7.6,\n",
       "                4.9,\n",
       "                7.3,\n",
       "                6.7,\n",
       "                7.2,\n",
       "                6.5,\n",
       "                6.4,\n",
       "                6.8,\n",
       "                5.7,\n",
       "                5.8,\n",
       "                6.4,\n",
       "                6.5,\n",
       "                7.7,\n",
       "                7.7,\n",
       "                6.0,\n",
       "                6.9,\n",
       "                5.6,\n",
       "                7.7,\n",
       "                6.3,\n",
       "                6.7,\n",
       "                7.2,\n",
       "                6.2,\n",
       "                6.1,\n",
       "                6.4,\n",
       "                7.2,\n",
       "                7.4,\n",
       "                7.9,\n",
       "                6.4,\n",
       "                6.3,\n",
       "                6.1,\n",
       "                7.7,\n",
       "                6.3,\n",
       "                6.4,\n",
       "                6.0,\n",
       "                6.9,\n",
       "                6.7,\n",
       "                6.9,\n",
       "                5.8,\n",
       "                6.8,\n",
       "                6.7,\n",
       "                6.7,\n",
       "                6.3,\n",
       "                6.5,\n",
       "                6.2,\n",
       "                5.9\n",
       "            ]\n",
       "        }\n",
       "    ],\n",
       "    \"yAxis\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"nameLocation\": \"middle\",\n",
       "            \"nameGap\": 25,\n",
       "            \"nameTextStyle\": {\n",
       "                \"fontSize\": 14\n",
       "            },\n",
       "            \"axisTick\": {\n",
       "                \"alignWithLabel\": false\n",
       "            },\n",
       "            \"inverse\": false,\n",
       "            \"boundaryGap\": true,\n",
       "            \"type\": \"value\",\n",
       "            \"splitLine\": {\n",
       "                \"show\": true\n",
       "            },\n",
       "            \"axisLabel\": {\n",
       "                \"interval\": \"auto\",\n",
       "                \"formatter\": \"{value} \",\n",
       "                \"rotate\": 0,\n",
       "                \"margin\": 8,\n",
       "                \"textStyle\": {\n",
       "                    \"fontSize\": 12\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\",\n",
       "        \"#f6f5ec\"\n",
       "    ]\n",
       "};\n",
       "myChart_640a54445ebb4318b5e9cebf0750b374.setOption(option_640a54445ebb4318b5e9cebf0750b374);\n",
       "\n",
       "    });\n",
       "</script>\n"
      ],
      "text/plain": [
       "<pyecharts.charts.scatter.Scatter at 0x17c6ba7e1d0>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X = iris.data[:, :2]\n",
    "y = iris.target\n",
    "\n",
    "scatter = Scatter('主标题', '副标题')\n",
    "scatter.add('first', X[y==0, 0], X[y==0, 1])\n",
    "scatter.add('second', X[y==1, 0], X[y==1, 1])\n",
    "scatter.add('third', X[y==2, 0], X[y==2, 1])\n",
    "scatter"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-07-07T12:33:07.325544Z",
     "start_time": "2018-07-07T12:33:07.272580Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts': '/nbextensions/echarts/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "    <div id=\"42533cde1f1549a2a2c78c83dbea77d8\" style=\"width:800px;height:400px;\"></div>\n",
       "\n",
       "\n",
       "<script>\n",
       "    require(['echarts'], function(echarts) {\n",
       "        \n",
       "var myChart_42533cde1f1549a2a2c78c83dbea77d8 = echarts.init(document.getElementById('42533cde1f1549a2a2c78c83dbea77d8'), 'light', {renderer: 'canvas'});\n",
       "\n",
       "var option_42533cde1f1549a2a2c78c83dbea77d8 = {\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u4e3b\\u6807\\u9898\",\n",
       "            \"subtext\": \"\\u526f\\u6807\\u9898\",\n",
       "            \"left\": \"auto\",\n",
       "            \"top\": \"auto\",\n",
       "            \"textStyle\": {\n",
       "                \"fontSize\": 18\n",
       "            },\n",
       "            \"subtextStyle\": {\n",
       "                \"fontSize\": 12\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"toolbox\": {\n",
       "        \"show\": true,\n",
       "        \"orient\": \"vertical\",\n",
       "        \"left\": \"95%\",\n",
       "        \"top\": \"center\",\n",
       "        \"feature\": {\n",
       "            \"saveAsImage\": {\n",
       "                \"show\": true,\n",
       "                \"title\": \"\\u4e0b\\u8f7d\\u56fe\\u7247\"\n",
       "            },\n",
       "            \"restore\": {\n",
       "                \"show\": true\n",
       "            },\n",
       "            \"dataView\": {\n",
       "                \"show\": true\n",
       "            }\n",
       "        }\n",
       "    },\n",
       "    \"series_id\": 5469754,\n",
       "    \"tooltip\": {\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"backgroundColor\": \"rgba(50,50,50,0.7)\",\n",
       "        \"borderColor\": \"#333\",\n",
       "        \"borderWidth\": 0\n",
       "    },\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"scatter\",\n",
       "            \"name\": \"first\",\n",
       "            \"symbol\": \"circle\",\n",
       "            \"symbolSize\": 10,\n",
       "            \"data\": [\n",
       "                [\n",
       "                    1.4,\n",
       "                    0.2\n",
       "                ],\n",
       "                [\n",
       "                    1.4,\n",
       "                    0.2\n",
       "                ],\n",
       "                [\n",
       "                    1.3,\n",
       "                    0.2\n",
       "                ],\n",
       "                [\n",
       "                    1.5,\n",
       "                    0.2\n",
       "                ],\n",
       "                [\n",
       "                    1.4,\n",
       "                    0.2\n",
       "                ],\n",
       "                [\n",
       "                    1.7,\n",
       "                    0.4\n",
       "                ],\n",
       "                [\n",
       "                    1.4,\n",
       "                    0.3\n",
       "                ],\n",
       "                [\n",
       "                    1.5,\n",
       "                    0.2\n",
       "                ],\n",
       "                [\n",
       "                    1.4,\n",
       "                    0.2\n",
       "                ],\n",
       "                [\n",
       "                    1.5,\n",
       "                    0.1\n",
       "                ],\n",
       "                [\n",
       "                    1.5,\n",
       "                    0.2\n",
       "                ],\n",
       "                [\n",
       "                    1.6,\n",
       "                    0.2\n",
       "                ],\n",
       "                [\n",
       "                    1.4,\n",
       "                    0.1\n",
       "                ],\n",
       "                [\n",
       "                    1.1,\n",
       "                    0.1\n",
       "                ],\n",
       "                [\n",
       "                    1.2,\n",
       "                    0.2\n",
       "                ],\n",
       "                [\n",
       "                    1.5,\n",
       "                    0.4\n",
       "                ],\n",
       "                [\n",
       "                    1.3,\n",
       "                    0.4\n",
       "                ],\n",
       "                [\n",
       "                    1.4,\n",
       "                    0.3\n",
       "                ],\n",
       "                [\n",
       "                    1.7,\n",
       "                    0.3\n",
       "                ],\n",
       "                [\n",
       "                    1.5,\n",
       "                    0.3\n",
       "                ],\n",
       "                [\n",
       "                    1.7,\n",
       "                    0.2\n",
       "                ],\n",
       "                [\n",
       "                    1.5,\n",
       "                    0.4\n",
       "                ],\n",
       "                [\n",
       "                    1.0,\n",
       "                    0.2\n",
       "                ],\n",
       "                [\n",
       "                    1.7,\n",
       "                    0.5\n",
       "                ],\n",
       "                [\n",
       "                    1.9,\n",
       "                    0.2\n",
       "                ],\n",
       "                [\n",
       "                    1.6,\n",
       "                    0.2\n",
       "                ],\n",
       "                [\n",
       "                    1.6,\n",
       "                    0.4\n",
       "                ],\n",
       "                [\n",
       "                    1.5,\n",
       "                    0.2\n",
       "                ],\n",
       "                [\n",
       "                    1.4,\n",
       "                    0.2\n",
       "                ],\n",
       "                [\n",
       "                    1.6,\n",
       "                    0.2\n",
       "                ],\n",
       "                [\n",
       "                    1.6,\n",
       "                    0.2\n",
       "                ],\n",
       "                [\n",
       "                    1.5,\n",
       "                    0.4\n",
       "                ],\n",
       "                [\n",
       "                    1.5,\n",
       "                    0.1\n",
       "                ],\n",
       "                [\n",
       "                    1.4,\n",
       "                    0.2\n",
       "                ],\n",
       "                [\n",
       "                    1.5,\n",
       "                    0.1\n",
       "                ],\n",
       "                [\n",
       "                    1.2,\n",
       "                    0.2\n",
       "                ],\n",
       "                [\n",
       "                    1.3,\n",
       "                    0.2\n",
       "                ],\n",
       "                [\n",
       "                    1.5,\n",
       "                    0.1\n",
       "                ],\n",
       "                [\n",
       "                    1.3,\n",
       "                    0.2\n",
       "                ],\n",
       "                [\n",
       "                    1.5,\n",
       "                    0.2\n",
       "                ],\n",
       "                [\n",
       "                    1.3,\n",
       "                    0.3\n",
       "                ],\n",
       "                [\n",
       "                    1.3,\n",
       "                    0.3\n",
       "                ],\n",
       "                [\n",
       "                    1.3,\n",
       "                    0.2\n",
       "                ],\n",
       "                [\n",
       "                    1.6,\n",
       "                    0.6\n",
       "                ],\n",
       "                [\n",
       "                    1.9,\n",
       "                    0.4\n",
       "                ],\n",
       "                [\n",
       "                    1.4,\n",
       "                    0.3\n",
       "                ],\n",
       "                [\n",
       "                    1.6,\n",
       "                    0.2\n",
       "                ],\n",
       "                [\n",
       "                    1.4,\n",
       "                    0.2\n",
       "                ],\n",
       "                [\n",
       "                    1.5,\n",
       "                    0.2\n",
       "                ],\n",
       "                [\n",
       "                    1.4,\n",
       "                    0.2\n",
       "                ]\n",
       "            ],\n",
       "            \"label\": {\n",
       "                \"normal\": {\n",
       "                    \"show\": false,\n",
       "                    \"position\": \"top\",\n",
       "                    \"textStyle\": {\n",
       "                        \"fontSize\": 12\n",
       "                    }\n",
       "                },\n",
       "                \"emphasis\": {\n",
       "                    \"show\": true,\n",
       "                    \"textStyle\": {\n",
       "                        \"fontSize\": 12\n",
       "                    }\n",
       "                }\n",
       "            },\n",
       "            \"markPoint\": {\n",
       "                \"data\": []\n",
       "            },\n",
       "            \"markLine\": {\n",
       "                \"data\": []\n",
       "            },\n",
       "            \"seriesId\": 5469754\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"scatter\",\n",
       "            \"name\": \"second\",\n",
       "            \"symbol\": \"circle\",\n",
       "            \"symbolSize\": 10,\n",
       "            \"data\": [\n",
       "                [\n",
       "                    4.7,\n",
       "                    1.4\n",
       "                ],\n",
       "                [\n",
       "                    4.5,\n",
       "                    1.5\n",
       "                ],\n",
       "                [\n",
       "                    4.9,\n",
       "                    1.5\n",
       "                ],\n",
       "                [\n",
       "                    4.0,\n",
       "                    1.3\n",
       "                ],\n",
       "                [\n",
       "                    4.6,\n",
       "                    1.5\n",
       "                ],\n",
       "                [\n",
       "                    4.5,\n",
       "                    1.3\n",
       "                ],\n",
       "                [\n",
       "                    4.7,\n",
       "                    1.6\n",
       "                ],\n",
       "                [\n",
       "                    3.3,\n",
       "                    1.0\n",
       "                ],\n",
       "                [\n",
       "                    4.6,\n",
       "                    1.3\n",
       "                ],\n",
       "                [\n",
       "                    3.9,\n",
       "                    1.4\n",
       "                ],\n",
       "                [\n",
       "                    3.5,\n",
       "                    1.0\n",
       "                ],\n",
       "                [\n",
       "                    4.2,\n",
       "                    1.5\n",
       "                ],\n",
       "                [\n",
       "                    4.0,\n",
       "                    1.0\n",
       "                ],\n",
       "                [\n",
       "                    4.7,\n",
       "                    1.4\n",
       "                ],\n",
       "                [\n",
       "                    3.6,\n",
       "                    1.3\n",
       "                ],\n",
       "                [\n",
       "                    4.4,\n",
       "                    1.4\n",
       "                ],\n",
       "                [\n",
       "                    4.5,\n",
       "                    1.5\n",
       "                ],\n",
       "                [\n",
       "                    4.1,\n",
       "                    1.0\n",
       "                ],\n",
       "                [\n",
       "                    4.5,\n",
       "                    1.5\n",
       "                ],\n",
       "                [\n",
       "                    3.9,\n",
       "                    1.1\n",
       "                ],\n",
       "                [\n",
       "                    4.8,\n",
       "                    1.8\n",
       "                ],\n",
       "                [\n",
       "                    4.0,\n",
       "                    1.3\n",
       "                ],\n",
       "                [\n",
       "                    4.9,\n",
       "                    1.5\n",
       "                ],\n",
       "                [\n",
       "                    4.7,\n",
       "                    1.2\n",
       "                ],\n",
       "                [\n",
       "                    4.3,\n",
       "                    1.3\n",
       "                ],\n",
       "                [\n",
       "                    4.4,\n",
       "                    1.4\n",
       "                ],\n",
       "                [\n",
       "                    4.8,\n",
       "                    1.4\n",
       "                ],\n",
       "                [\n",
       "                    5.0,\n",
       "                    1.7\n",
       "                ],\n",
       "                [\n",
       "                    4.5,\n",
       "                    1.5\n",
       "                ],\n",
       "                [\n",
       "                    3.5,\n",
       "                    1.0\n",
       "                ],\n",
       "                [\n",
       "                    3.8,\n",
       "                    1.1\n",
       "                ],\n",
       "                [\n",
       "                    3.7,\n",
       "                    1.0\n",
       "                ],\n",
       "                [\n",
       "                    3.9,\n",
       "                    1.2\n",
       "                ],\n",
       "                [\n",
       "                    5.1,\n",
       "                    1.6\n",
       "                ],\n",
       "                [\n",
       "                    4.5,\n",
       "                    1.5\n",
       "                ],\n",
       "                [\n",
       "                    4.5,\n",
       "                    1.6\n",
       "                ],\n",
       "                [\n",
       "                    4.7,\n",
       "                    1.5\n",
       "                ],\n",
       "                [\n",
       "                    4.4,\n",
       "                    1.3\n",
       "                ],\n",
       "                [\n",
       "                    4.1,\n",
       "                    1.3\n",
       "                ],\n",
       "                [\n",
       "                    4.0,\n",
       "                    1.3\n",
       "                ],\n",
       "                [\n",
       "                    4.4,\n",
       "                    1.2\n",
       "                ],\n",
       "                [\n",
       "                    4.6,\n",
       "                    1.4\n",
       "                ],\n",
       "                [\n",
       "                    4.0,\n",
       "                    1.2\n",
       "                ],\n",
       "                [\n",
       "                    3.3,\n",
       "                    1.0\n",
       "                ],\n",
       "                [\n",
       "                    4.2,\n",
       "                    1.3\n",
       "                ],\n",
       "                [\n",
       "                    4.2,\n",
       "                    1.2\n",
       "                ],\n",
       "                [\n",
       "                    4.2,\n",
       "                    1.3\n",
       "                ],\n",
       "                [\n",
       "                    4.3,\n",
       "                    1.3\n",
       "                ],\n",
       "                [\n",
       "                    3.0,\n",
       "                    1.1\n",
       "                ],\n",
       "                [\n",
       "                    4.1,\n",
       "                    1.3\n",
       "                ]\n",
       "            ],\n",
       "            \"label\": {\n",
       "                \"normal\": {\n",
       "                    \"show\": false,\n",
       "                    \"position\": \"top\",\n",
       "                    \"textStyle\": {\n",
       "                        \"fontSize\": 12\n",
       "                    }\n",
       "                },\n",
       "                \"emphasis\": {\n",
       "                    \"show\": true,\n",
       "                    \"textStyle\": {\n",
       "                        \"fontSize\": 12\n",
       "                    }\n",
       "                }\n",
       "            },\n",
       "            \"markPoint\": {\n",
       "                \"data\": []\n",
       "            },\n",
       "            \"markLine\": {\n",
       "                \"data\": []\n",
       "            },\n",
       "            \"seriesId\": 5469754\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"scatter\",\n",
       "            \"name\": \"third\",\n",
       "            \"symbol\": \"circle\",\n",
       "            \"symbolSize\": 10,\n",
       "            \"data\": [\n",
       "                [\n",
       "                    6.0,\n",
       "                    2.5\n",
       "                ],\n",
       "                [\n",
       "                    5.1,\n",
       "                    1.9\n",
       "                ],\n",
       "                [\n",
       "                    5.9,\n",
       "                    2.1\n",
       "                ],\n",
       "                [\n",
       "                    5.6,\n",
       "                    1.8\n",
       "                ],\n",
       "                [\n",
       "                    5.8,\n",
       "                    2.2\n",
       "                ],\n",
       "                [\n",
       "                    6.6,\n",
       "                    2.1\n",
       "                ],\n",
       "                [\n",
       "                    4.5,\n",
       "                    1.7\n",
       "                ],\n",
       "                [\n",
       "                    6.3,\n",
       "                    1.8\n",
       "                ],\n",
       "                [\n",
       "                    5.8,\n",
       "                    1.8\n",
       "                ],\n",
       "                [\n",
       "                    6.1,\n",
       "                    2.5\n",
       "                ],\n",
       "                [\n",
       "                    5.1,\n",
       "                    2.0\n",
       "                ],\n",
       "                [\n",
       "                    5.3,\n",
       "                    1.9\n",
       "                ],\n",
       "                [\n",
       "                    5.5,\n",
       "                    2.1\n",
       "                ],\n",
       "                [\n",
       "                    5.0,\n",
       "                    2.0\n",
       "                ],\n",
       "                [\n",
       "                    5.1,\n",
       "                    2.4\n",
       "                ],\n",
       "                [\n",
       "                    5.3,\n",
       "                    2.3\n",
       "                ],\n",
       "                [\n",
       "                    5.5,\n",
       "                    1.8\n",
       "                ],\n",
       "                [\n",
       "                    6.7,\n",
       "                    2.2\n",
       "                ],\n",
       "                [\n",
       "                    6.9,\n",
       "                    2.3\n",
       "                ],\n",
       "                [\n",
       "                    5.0,\n",
       "                    1.5\n",
       "                ],\n",
       "                [\n",
       "                    5.7,\n",
       "                    2.3\n",
       "                ],\n",
       "                [\n",
       "                    4.9,\n",
       "                    2.0\n",
       "                ],\n",
       "                [\n",
       "                    6.7,\n",
       "                    2.0\n",
       "                ],\n",
       "                [\n",
       "                    4.9,\n",
       "                    1.8\n",
       "                ],\n",
       "                [\n",
       "                    5.7,\n",
       "                    2.1\n",
       "                ],\n",
       "                [\n",
       "                    6.0,\n",
       "                    1.8\n",
       "                ],\n",
       "                [\n",
       "                    4.8,\n",
       "                    1.8\n",
       "                ],\n",
       "                [\n",
       "                    4.9,\n",
       "                    1.8\n",
       "                ],\n",
       "                [\n",
       "                    5.6,\n",
       "                    2.1\n",
       "                ],\n",
       "                [\n",
       "                    5.8,\n",
       "                    1.6\n",
       "                ],\n",
       "                [\n",
       "                    6.1,\n",
       "                    1.9\n",
       "                ],\n",
       "                [\n",
       "                    6.4,\n",
       "                    2.0\n",
       "                ],\n",
       "                [\n",
       "                    5.6,\n",
       "                    2.2\n",
       "                ],\n",
       "                [\n",
       "                    5.1,\n",
       "                    1.5\n",
       "                ],\n",
       "                [\n",
       "                    5.6,\n",
       "                    1.4\n",
       "                ],\n",
       "                [\n",
       "                    6.1,\n",
       "                    2.3\n",
       "                ],\n",
       "                [\n",
       "                    5.6,\n",
       "                    2.4\n",
       "                ],\n",
       "                [\n",
       "                    5.5,\n",
       "                    1.8\n",
       "                ],\n",
       "                [\n",
       "                    4.8,\n",
       "                    1.8\n",
       "                ],\n",
       "                [\n",
       "                    5.4,\n",
       "                    2.1\n",
       "                ],\n",
       "                [\n",
       "                    5.6,\n",
       "                    2.4\n",
       "                ],\n",
       "                [\n",
       "                    5.1,\n",
       "                    2.3\n",
       "                ],\n",
       "                [\n",
       "                    5.1,\n",
       "                    1.9\n",
       "                ],\n",
       "                [\n",
       "                    5.9,\n",
       "                    2.3\n",
       "                ],\n",
       "                [\n",
       "                    5.7,\n",
       "                    2.5\n",
       "                ],\n",
       "                [\n",
       "                    5.2,\n",
       "                    2.3\n",
       "                ],\n",
       "                [\n",
       "                    5.0,\n",
       "                    1.9\n",
       "                ],\n",
       "                [\n",
       "                    5.2,\n",
       "                    2.0\n",
       "                ],\n",
       "                [\n",
       "                    5.4,\n",
       "                    2.3\n",
       "                ],\n",
       "                [\n",
       "                    5.1,\n",
       "                    1.8\n",
       "                ]\n",
       "            ],\n",
       "            \"label\": {\n",
       "                \"normal\": {\n",
       "                    \"show\": false,\n",
       "                    \"position\": \"top\",\n",
       "                    \"textStyle\": {\n",
       "                        \"fontSize\": 12\n",
       "                    }\n",
       "                },\n",
       "                \"emphasis\": {\n",
       "                    \"show\": true,\n",
       "                    \"textStyle\": {\n",
       "                        \"fontSize\": 12\n",
       "                    }\n",
       "                }\n",
       "            },\n",
       "            \"markPoint\": {\n",
       "                \"data\": []\n",
       "            },\n",
       "            \"markLine\": {\n",
       "                \"data\": []\n",
       "            },\n",
       "            \"seriesId\": 5469754\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"first\",\n",
       "                \"second\",\n",
       "                \"third\"\n",
       "            ],\n",
       "            \"selectedMode\": \"multiple\",\n",
       "            \"show\": true,\n",
       "            \"left\": \"center\",\n",
       "            \"top\": \"top\",\n",
       "            \"orient\": \"horizontal\",\n",
       "            \"textStyle\": {\n",
       "                \"fontSize\": 12\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"xAxis\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"nameLocation\": \"middle\",\n",
       "            \"nameGap\": 25,\n",
       "            \"nameTextStyle\": {\n",
       "                \"fontSize\": 14\n",
       "            },\n",
       "            \"axisTick\": {\n",
       "                \"alignWithLabel\": false\n",
       "            },\n",
       "            \"inverse\": false,\n",
       "            \"boundaryGap\": true,\n",
       "            \"type\": \"value\",\n",
       "            \"splitLine\": {\n",
       "                \"show\": true\n",
       "            },\n",
       "            \"axisLabel\": {\n",
       "                \"interval\": \"auto\",\n",
       "                \"rotate\": 0,\n",
       "                \"margin\": 8,\n",
       "                \"textStyle\": {\n",
       "                    \"fontSize\": 12\n",
       "                }\n",
       "            },\n",
       "            \"data\": [\n",
       "                6.0,\n",
       "                5.1,\n",
       "                5.9,\n",
       "                5.6,\n",
       "                5.8,\n",
       "                6.6,\n",
       "                4.5,\n",
       "                6.3,\n",
       "                5.8,\n",
       "                6.1,\n",
       "                5.1,\n",
       "                5.3,\n",
       "                5.5,\n",
       "                5.0,\n",
       "                5.1,\n",
       "                5.3,\n",
       "                5.5,\n",
       "                6.7,\n",
       "                6.9,\n",
       "                5.0,\n",
       "                5.7,\n",
       "                4.9,\n",
       "                6.7,\n",
       "                4.9,\n",
       "                5.7,\n",
       "                6.0,\n",
       "                4.8,\n",
       "                4.9,\n",
       "                5.6,\n",
       "                5.8,\n",
       "                6.1,\n",
       "                6.4,\n",
       "                5.6,\n",
       "                5.1,\n",
       "                5.6,\n",
       "                6.1,\n",
       "                5.6,\n",
       "                5.5,\n",
       "                4.8,\n",
       "                5.4,\n",
       "                5.6,\n",
       "                5.1,\n",
       "                5.1,\n",
       "                5.9,\n",
       "                5.7,\n",
       "                5.2,\n",
       "                5.0,\n",
       "                5.2,\n",
       "                5.4,\n",
       "                5.1\n",
       "            ]\n",
       "        }\n",
       "    ],\n",
       "    \"yAxis\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"nameLocation\": \"middle\",\n",
       "            \"nameGap\": 25,\n",
       "            \"nameTextStyle\": {\n",
       "                \"fontSize\": 14\n",
       "            },\n",
       "            \"axisTick\": {\n",
       "                \"alignWithLabel\": false\n",
       "            },\n",
       "            \"inverse\": false,\n",
       "            \"boundaryGap\": true,\n",
       "            \"type\": \"value\",\n",
       "            \"splitLine\": {\n",
       "                \"show\": true\n",
       "            },\n",
       "            \"axisLabel\": {\n",
       "                \"interval\": \"auto\",\n",
       "                \"formatter\": \"{value} \",\n",
       "                \"rotate\": 0,\n",
       "                \"margin\": 8,\n",
       "                \"textStyle\": {\n",
       "                    \"fontSize\": 12\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\",\n",
       "        \"#f6f5ec\"\n",
       "    ]\n",
       "};\n",
       "myChart_42533cde1f1549a2a2c78c83dbea77d8.setOption(option_42533cde1f1549a2a2c78c83dbea77d8);\n",
       "\n",
       "    });\n",
       "</script>\n"
      ],
      "text/plain": [
       "<pyecharts.charts.scatter.Scatter at 0x21481a30748>"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X = iris.data[:, 2:]\n",
    "y = iris.target\n",
    "\n",
    "scatter = Scatter('主标题', '副标题')\n",
    "scatter.add('first', X[y==0, 0], X[y==0, 1])\n",
    "scatter.add('second', X[y==1, 0], X[y==1, 1])\n",
    "scatter.add('third', X[y==2, 0], X[y==2, 1])\n",
    "scatter"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-07-07T12:41:51.788833Z",
     "start_time": "2018-07-07T12:41:51.781836Z"
    }
   },
   "source": [
    "# K近邻算法概述"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-07-07T13:36:13.881884Z",
     "start_time": "2018-07-07T13:36:13.869893Z"
    }
   },
   "outputs": [],
   "source": [
    "raw_data_X = [[3.4, 2.3], [3.1, 1.78], [1.34, 3.36], [3.5, 4.6],\n",
    "             [2.2, 2.8], [7.4, 4.6], [5.74, 3.53], [9.1, 2.5],\n",
    "             [7.78, 3.4], [7.9, 0.79]]\n",
    "raw_data_y = [0,0,0,0,0, 1,1,1,1,1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-07-07T13:37:53.471051Z",
     "start_time": "2018-07-07T13:37:53.423080Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts': '/nbextensions/echarts/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "    <div id=\"885f8e93c8a444f1a37f2906806b0dea\" style=\"width:800px;height:400px;\"></div>\n",
       "\n",
       "\n",
       "<script>\n",
       "    require(['echarts'], function(echarts) {\n",
       "        \n",
       "var myChart_885f8e93c8a444f1a37f2906806b0dea = echarts.init(document.getElementById('885f8e93c8a444f1a37f2906806b0dea'), 'light', {renderer: 'canvas'});\n",
       "\n",
       "var option_885f8e93c8a444f1a37f2906806b0dea = {\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u4e3b\\u6807\\u9898\",\n",
       "            \"subtext\": \"\\u526f\\u6807\\u9898\",\n",
       "            \"left\": \"auto\",\n",
       "            \"top\": \"auto\",\n",
       "            \"textStyle\": {\n",
       "                \"fontSize\": 18\n",
       "            },\n",
       "            \"subtextStyle\": {\n",
       "                \"fontSize\": 12\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"toolbox\": {\n",
       "        \"show\": true,\n",
       "        \"orient\": \"vertical\",\n",
       "        \"left\": \"95%\",\n",
       "        \"top\": \"center\",\n",
       "        \"feature\": {\n",
       "            \"saveAsImage\": {\n",
       "                \"show\": true,\n",
       "                \"title\": \"\\u4e0b\\u8f7d\\u56fe\\u7247\"\n",
       "            },\n",
       "            \"restore\": {\n",
       "                \"show\": true\n",
       "            },\n",
       "            \"dataView\": {\n",
       "                \"show\": true\n",
       "            }\n",
       "        }\n",
       "    },\n",
       "    \"series_id\": 1378376,\n",
       "    \"tooltip\": {\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"backgroundColor\": \"rgba(50,50,50,0.7)\",\n",
       "        \"borderColor\": \"#333\",\n",
       "        \"borderWidth\": 0\n",
       "    },\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"scatter\",\n",
       "            \"name\": \"y = 0\",\n",
       "            \"symbol\": \"circle\",\n",
       "            \"symbolSize\": 10,\n",
       "            \"data\": [\n",
       "                [\n",
       "                    3.4,\n",
       "                    2.3\n",
       "                ],\n",
       "                [\n",
       "                    3.1,\n",
       "                    1.78\n",
       "                ],\n",
       "                [\n",
       "                    1.34,\n",
       "                    3.36\n",
       "                ],\n",
       "                [\n",
       "                    3.5,\n",
       "                    4.6\n",
       "                ],\n",
       "                [\n",
       "                    2.2,\n",
       "                    2.8\n",
       "                ]\n",
       "            ],\n",
       "            \"label\": {\n",
       "                \"normal\": {\n",
       "                    \"show\": false,\n",
       "                    \"position\": \"top\",\n",
       "                    \"textStyle\": {\n",
       "                        \"fontSize\": 12\n",
       "                    }\n",
       "                },\n",
       "                \"emphasis\": {\n",
       "                    \"show\": true,\n",
       "                    \"textStyle\": {\n",
       "                        \"fontSize\": 12\n",
       "                    }\n",
       "                }\n",
       "            },\n",
       "            \"markPoint\": {\n",
       "                \"data\": []\n",
       "            },\n",
       "            \"markLine\": {\n",
       "                \"data\": []\n",
       "            },\n",
       "            \"seriesId\": 1378376\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"scatter\",\n",
       "            \"name\": \"y = 1\",\n",
       "            \"symbol\": \"circle\",\n",
       "            \"symbolSize\": 10,\n",
       "            \"data\": [\n",
       "                [\n",
       "                    7.4,\n",
       "                    4.6\n",
       "                ],\n",
       "                [\n",
       "                    5.74,\n",
       "                    3.53\n",
       "                ],\n",
       "                [\n",
       "                    9.1,\n",
       "                    2.5\n",
       "                ],\n",
       "                [\n",
       "                    7.78,\n",
       "                    3.4\n",
       "                ],\n",
       "                [\n",
       "                    7.9,\n",
       "                    0.79\n",
       "                ]\n",
       "            ],\n",
       "            \"label\": {\n",
       "                \"normal\": {\n",
       "                    \"show\": false,\n",
       "                    \"position\": \"top\",\n",
       "                    \"textStyle\": {\n",
       "                        \"fontSize\": 12\n",
       "                    }\n",
       "                },\n",
       "                \"emphasis\": {\n",
       "                    \"show\": true,\n",
       "                    \"textStyle\": {\n",
       "                        \"fontSize\": 12\n",
       "                    }\n",
       "                }\n",
       "            },\n",
       "            \"markPoint\": {\n",
       "                \"data\": []\n",
       "            },\n",
       "            \"markLine\": {\n",
       "                \"data\": []\n",
       "            },\n",
       "            \"seriesId\": 1378376\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"y = 0\",\n",
       "                \"y = 1\"\n",
       "            ],\n",
       "            \"selectedMode\": \"multiple\",\n",
       "            \"show\": true,\n",
       "            \"left\": \"center\",\n",
       "            \"top\": \"top\",\n",
       "            \"orient\": \"horizontal\",\n",
       "            \"textStyle\": {\n",
       "                \"fontSize\": 12\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"xAxis\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"nameLocation\": \"middle\",\n",
       "            \"nameGap\": 25,\n",
       "            \"nameTextStyle\": {\n",
       "                \"fontSize\": 14\n",
       "            },\n",
       "            \"axisTick\": {\n",
       "                \"alignWithLabel\": false\n",
       "            },\n",
       "            \"inverse\": false,\n",
       "            \"boundaryGap\": true,\n",
       "            \"type\": \"value\",\n",
       "            \"splitLine\": {\n",
       "                \"show\": true\n",
       "            },\n",
       "            \"axisLabel\": {\n",
       "                \"interval\": \"auto\",\n",
       "                \"rotate\": 0,\n",
       "                \"margin\": 8,\n",
       "                \"textStyle\": {\n",
       "                    \"fontSize\": 12\n",
       "                }\n",
       "            },\n",
       "            \"data\": [\n",
       "                7.4,\n",
       "                5.74,\n",
       "                9.1,\n",
       "                7.78,\n",
       "                7.9\n",
       "            ]\n",
       "        }\n",
       "    ],\n",
       "    \"yAxis\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"nameLocation\": \"middle\",\n",
       "            \"nameGap\": 25,\n",
       "            \"nameTextStyle\": {\n",
       "                \"fontSize\": 14\n",
       "            },\n",
       "            \"axisTick\": {\n",
       "                \"alignWithLabel\": false\n",
       "            },\n",
       "            \"inverse\": false,\n",
       "            \"boundaryGap\": true,\n",
       "            \"type\": \"value\",\n",
       "            \"splitLine\": {\n",
       "                \"show\": true\n",
       "            },\n",
       "            \"axisLabel\": {\n",
       "                \"interval\": \"auto\",\n",
       "                \"formatter\": \"{value} \",\n",
       "                \"rotate\": 0,\n",
       "                \"margin\": 8,\n",
       "                \"textStyle\": {\n",
       "                    \"fontSize\": 12\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\",\n",
       "        \"#f6f5ec\"\n",
       "    ]\n",
       "};\n",
       "myChart_885f8e93c8a444f1a37f2906806b0dea.setOption(option_885f8e93c8a444f1a37f2906806b0dea);\n",
       "\n",
       "    });\n",
       "</script>\n"
      ],
      "text/plain": [
       "<pyecharts.charts.scatter.Scatter at 0x206932e76a0>"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X_train = np.array(raw_data_X)\n",
    "y_train = np.array(raw_data_y)\n",
    "\n",
    "x = np.array([8, 3.34])\n",
    "\n",
    "scatter = Scatter('主标题', '副标题')\n",
    "scatter.add('y = 0', X_train[y_train==0, 0], X_train[y_train==0, 1])\n",
    "scatter.add('y = 1', X_train[y_train==1, 0], X_train[y_train==1, 1])\n",
    "# scatter.add('y = ?', x.reshape(1,-1)[0], x.reshape(1,-1)[1])\n",
    "scatter"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-07-07T13:08:37.312670Z",
     "start_time": "2018-07-07T13:08:37.291685Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[4.716100083755645,\n",
       " 5.142334100386711,\n",
       " 6.660030029962328,\n",
       " 4.673071794868981,\n",
       " 5.825083690385916,\n",
       " 1.3955644019535605,\n",
       " 2.2679726629745782,\n",
       " 1.384052022143676,\n",
       " 0.22803508501982736,\n",
       " 2.551960031034969]"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 计算欧拉距离\n",
    "from math import sqrt\n",
    "\n",
    "distances = []\n",
    "# for x_train in X_train:\n",
    "#     d = sqrt(np.sum((x_train - x)**2))\n",
    "#     distances.append(d)\n",
    "    \n",
    "distances = [sqrt(np.sum((x_train - x)**2)) for x_train in X_train]\n",
    "distances"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-07-07T13:11:09.515628Z",
     "start_time": "2018-07-07T13:11:09.500642Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 1, 1, 1, 1, 0]"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nearest = np.argsort(distances)  # 获得排序后的索引值\n",
    "k = 6\n",
    "topK_y = [y_train[i] for i in nearest[:k]] # 距离最近的6个点\n",
    "topK_y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-07-07T13:11:32.122479Z",
     "start_time": "2018-07-07T13:11:32.114487Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Counter({0: 1, 1: 5})"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from collections import Counter\n",
    "Counter(topK_y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-07-07T13:13:14.127739Z",
     "start_time": "2018-07-07T13:13:14.117745Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[(1, 5)]"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "votes = Counter(topK_y)\n",
    "votes.most_common(1)   # 最多出现的1个值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-07-07T13:14:10.989981Z",
     "start_time": "2018-07-07T13:14:10.980984Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "predict_y = votes.most_common(1)[0][0]\n",
    "predict_y"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 测试下同目录下的py文件"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-07-07T13:24:59.112275Z",
     "start_time": "2018-07-07T13:24:59.106283Z"
    }
   },
   "outputs": [],
   "source": [
    "%run c1_KNN.py"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-07-07T13:27:30.306287Z",
     "start_time": "2018-07-07T13:27:30.282300Z"
    }
   },
   "outputs": [],
   "source": [
    "raw_data_X = [[3.4, 2.3], [3.1, 1.78], [1.34, 3.36], [3.5, 4.6],\n",
    "             [2.2, 2.8], [7.4, 4.6], [5.74, 3.53], [9.1, 2.5],\n",
    "             [7.78, 3.4], [7.9, 0.79]]\n",
    "raw_data_y = [0,0,0,0,0, 1,1,1,1,1]\n",
    "\n",
    "X_train = np.array(raw_data_X)\n",
    "y_train = np.array(raw_data_y)\n",
    "\n",
    "x = np.array([8, 3.34])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-07-07T13:28:13.145862Z",
     "start_time": "2018-07-07T13:28:13.122876Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "predict_y = KNN_classifiy(6, X_train, y_train, x)\n",
    "predict_y"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 使用scikit-learn中的KNN"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-07-07T13:32:43.899167Z",
     "start_time": "2018-07-07T13:32:43.893167Z"
    }
   },
   "outputs": [],
   "source": [
    "from sklearn.neighbors import KNeighborsClassifier"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-07-07T13:33:28.813864Z",
     "start_time": "2018-07-07T13:33:28.803873Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "KNeighborsClassifier(algorithm='auto', leaf_size=30, metric='minkowski',\n",
       "           metric_params=None, n_jobs=1, n_neighbors=6, p=2,\n",
       "           weights='uniform')"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "kNN_classifier = KNeighborsClassifier(n_neighbors=6)\n",
    "kNN_classifier.fit(X_train, y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2018-07-07T13:35:30.204218Z",
     "start_time": "2018-07-07T13:35:30.099281Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1])"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = np.array([8, 3.34])\n",
    "kNN_classifier.predict(x.reshape(1,-1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  },
  "latex_envs": {
   "LaTeX_envs_menu_present": true,
   "autoclose": false,
   "autocomplete": true,
   "bibliofile": "biblio.bib",
   "cite_by": "apalike",
   "current_citInitial": 1.0,
   "eqLabelWithNumbers": true,
   "eqNumInitial": 1.0,
   "hotkeys": {
    "equation": "Ctrl-E",
    "itemize": "Ctrl-I"
   },
   "labels_anchors": false,
   "latex_user_defs": false,
   "report_style_numbering": false,
   "user_envs_cfg": false
  },
  "nbTranslate": {
   "displayLangs": [
    "*"
   ],
   "hotkey": "alt-t",
   "langInMainMenu": true,
   "sourceLang": "en",
   "targetLang": "fr",
   "useGoogleTranslate": true
  },
  "toc": {
   "base_numbering": 1.0,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16.0,
    "lenType": 16.0,
    "lenVar": 40.0
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
